import request from './apiConfing'

export async function findAllRoom() {
  return request({
    method: 'get',
    url: '/room/selectAll'
  })
}

export function findRoomBySize(size) {
  return request({
    url: `/room/uselectbysize?size=${size}`,
    method: 'get'
  })
}

/**
 * 
 * @param {object} data
 * @param {number} data.startTime
 * @param {number} data.endTime
 */
export function findRoomByStartAndEndTime(data) {
  return request({
    url: '/room/selectbytime',
    method: 'post',
    data
  })
}

export function findRoomByStartAndEndTimeAndSize(data) {
  return request({
    url: '/room/selectbyall',
    method: 'post',
    data,
  })
}

export function findMeetingByInviteCode({ inviteCode }) {
  return request({
    url: `/meeting/selectbyinvitecode?inviteCode=${inviteCode}`,
    method: 'get'
    // data: {
    //   inviteCode
    // }
  })
}

export function joinMeetingByInviteCode(inviteCode) {
  return request({
    url: `/meeting/join?inviteCode=${inviteCode}`,
    method: 'get'
  })
}

/**
 * 
 * @param {object} meeting 会议信息
 * @param {string} meeting.theme 会议主题
 * @param {number} meeting.startTime
 * @param {number} meeting.endTime
 * @param {string} meeting.room
 * @param {string} meeting.isSigned 是否需要签到
 * @param {number} meeting.size 预期人数
 */
export function addMeeting(meeting) {
  return request({
    url: '/meeting/add',
    method: 'post',
    data: meeting,
  })
}

export function findAllMyOrderedMeetings() {
  return request({
    url: '/meeting/selectbyorder',
    method: 'get'
  })
}

export function findAllMyJoinedMeetings() {
  return request({
    url: '/meeting/selectbyjoin',
    method: 'get'
  })
}

export function findAllMyAllMeetings() {
  return request({
    url: '/meeting/selectall',
    method: 'get'
  })
}

export function getMeetingMember(meetingId, id) {
  return request({
    url: `/meeting/getjoiner?meeting=${meetingId}&id=${id}`,
    method: 'get'
  })
}

export function removeMeetingMember(meetingId, memberId) {
  return request({
    url: '/meeting/deletejoiner',
    method: 'post',
    data: {
      meeting: meetingId,
      joiner: memberId,
    }
  })
}
